


//
//  xsudokuViewController.m
//  pubSudoku
//
//  Created by richard_local on 28/08/13.
//  Copyright (c) 2013 ierdre.com. All rights reserved.
//

#import "xsudokuViewController.h"

@interface xsudokuViewController ()

@end

@implementation xsudokuViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}
- (id)initWithCoder:(NSCoder *)decoder{
    UCases = [[ NSMutableArray alloc] init];
    [self initData];
    NSLog (@" INITttttttttt \n");
    
    return [super initWithCoder:decoder];
    
    
}
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:0.92]

//Then use any Hex value


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.banner setAlpha:0];
    self.banner.delegate = self;
    [self drawGrid];
    //[self.view setBackgroundColor:UIColorFromRGB(0xEEDFA6)];


	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


// ici j'initialise la grille en créant les boutons
// Création bouton
// TO DO alimentation initiale avec la grille sudoku

// J'ai besoin de deux methodes
// une qui init la structure de donnéées des boutons
// Une qui modifie la structure des données en fonction de la grille sudoku
// et une qui affiche le contenu
float xx[]={1,36,71,107,143,177,214,249,285};
int yy[]={50,85,120,157,192,227,264,299,334};
#define CASE_SIZE 33 
-(void) drawGrid{
    for (int i=0; i<81 ; i ++ ){
        UIButton *button  = [UCases objectAtIndex:i];
        [button removeFromSuperview];
        [self.viewGrid addSubview:button];
    }
}
-(void) initData{
    for (int y=0 ; y < 9 ; y ++ ) {
        for (int x=0 ; x<9; x++){
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            //NSLog(@" %d %d",xx[x], yy[y]);
            //[button addTarget:self
            //         action:@selector(aMethod:)
            //forControlEvents:UIControlEventTouchDown];
            NSString *title = [[NSString alloc] initWithFormat:@"%d",x ];
            [button setTitle:title forState:UIControlStateNormal];
        
            [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20.0]];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            
            [button setBackgroundColor:[UIColor grayColor] ];
            
            button.frame = CGRectMake(xx[x], yy[y], CASE_SIZE, CASE_SIZE);
           // [button setImage:[UIImage imageNamed:@"Highlight.png"] forState:UIControlStateHighlighted];

            
            [UCases addObject:button];
           // [self.viewGrid addSubview:button];
        }
    }
    
    
    
}



//Banner IAD
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    return YES;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    [self.banner setAlpha:0];

}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
  
    NSLog(@"ERROR WHEN LOAD BANNER %@",error);
    [banner setAlpha:0];
}

@end
